import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { ScrollBarDirection } from "../../../../fl/controls/ScrollBarDirection";
import { BlessListCellRenderer } from "./BlessListCellRenderer";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SFriendBlessSucess } from "../../../../Message/Public/SFriendBlessSucess";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _blesses } from "../../../../this/_blesses";
type int = number;
//class FriendBlessReceivePanel
    
    export  class FriendBlessReceivePanel extends BaseWindow
    {
        constructor()
        {
            super();
            this._blesses = [];
            this.setSize(513, 370);
            title = Language.getString(69416);
            this.titleHeight = 26;
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc2=null;
            super.createChildren();
            ObjCreate.createBg(14, 38, 485, 285, this);
            var loc1=0;
            while (loc1 < 8) 
            {
                loc2 = ResouceConst.getScaleBitmap(ImagesConst.SplitLine);
                loc2.x = 20;
                loc2.y = 66 + loc1 * 29;
                loc2.width = 474;
                loc2.height = 2;
                this.addChild(loc2);
                ++loc1;
            }
            ObjCreate.createLabel(Language.getString(69417), 39, 45, 45, 20, flash.text.TextFormatAlign.LEFT, this, true, 16711368);
            ObjCreate.createLabel(Language.getString(69418), 110, 45, 45, 20, flash.text.TextFormatAlign.LEFT, this, true, 16711368);
            ObjCreate.createLabel(Language.getString(69419), 205, 45, 45, 20, flash.text.TextFormatAlign.LEFT, this, true, 16711368);
            ObjCreate.createLabel(Language.getString(69420), 260, 45, 45, 20, flash.text.TextFormatAlign.LEFT, this, true, 16711368);
            ObjCreate.createLabel(Language.getString(69421), 370, 45, 70, 20, flash.text.TextFormatAlign.LEFT, this, true, 16711368);
            this._blessList = ObjCreate.createTileList(20, 63, 470, 215, this);
            this._blessList.direction = ScrollBarDirection.VERTICAL;
            this._blessList.columnWidth = 470;
            this._blessList.rowHeight = 30;
            this._blessList.setStyle("cellRenderer", BlessListCellRenderer);
            this._pageBtn = ObjCreate.createPageSelecter(191, 276, this);
            this._pageBtn.mode = PageSelecter.CompleteMode;
            this._pageBtn.addEventListener(flash.events.Event.CHANGE, this.onPageChangeHandler);
            this._allExpLabel = ObjCreate.createLabel("", 145, 299, 275, 20, flash.text.TextFormatAlign.LEFT, this, false, 16711368);
            this._OkBtn = ObjCreate.createGButton(Language.getString(69901), 218, 331, 70, 26, this, "ButtonSpecial");
            this._OkBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkButtonClick);
            return;
        }

        public showBlessReceive(arg1: Array<any>): void
        {
            var loc1=0;
            loc1 = 0;
            while (loc1 < arg1.length) 
            {
                this._blesses.push(arg1[loc1]);
                ++loc1;
            }
            this._pageBtn.maxPage = Math.ceil(this._blesses.length / this.rowCount);
            this.updateShowList();
            this.updateAllExp();
            this.show();
            return;
        }

        /* internal  */onPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.updateShowList();
            return;
        }

        /* internal  */onOkButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */updateShowList(): void
        {
            var loc1=[];
            var loc2=(this._pageBtn.currentPage - 1) * this.rowCount;
            var loc3=Math.min((this._pageBtn.currentPage * this.rowCount - 1), (this._blesses.length - 1));
            var loc4=loc2;
            while (loc4 <= loc3) 
            {
                loc1.push({"ordinal": loc4 + 1, "bless": _blesses[loc4]});
                ++loc4;
            }
            this._blessList.dataProvider = new DataProvider(loc1);
            return;
        }

        /* internal  */updateAllExp(): void
        {
            var loc1=0;
            var loc2=0;
            while (loc2 < this._blesses.length) 
            {
                loc1 = loc1 + (this._blesses[loc2] as SFriendBlessSucess).blessRewardExp;
                ++loc2;
            }
            this._allExpLabel.text = Language.getString(69422) + loc1;
            return;
        }

        protected /* override */ updateSize(): void
        {
            super.updateSize();
            this._windowCenter.height = 295;
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._blesses = [];
            this._pageBtn.currentPage = 1;
            this._blessList.dataProvider = new DataProvider(this._blesses);
            return;
        }

        public /* var */rowCount: int=7;

        /* internal */ /* var */_blessList: GTileList;

        /* internal */ /* var */_blesses: Array<any>;

        /* internal */ /* var */_pageBtn: PageSelecter;

        /* internal */ /* var */_allExpLabel: GLabel;

        /* internal */ /* var */_OkBtn: GButton;
    }
